package com.example.zsfinacialmanage.activity;
import android.annotation.SuppressLint;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import com.example.zsfinacialmanage.R;
import com.example.zsfinacialmanage.adapter.IncomeAdapter;
import com.example.zsfinacialmanage.adapter.OutpayAdapter;
import com.example.zsfinacialmanage.bean.IncomeBean;
import com.example.zsfinacialmanage.bean.OutpayBean;
import com.example.zsfinacialmanage.utils.MyDBHelper;

import java.util.ArrayList;
import java.util.List;

public class PayDetailActivity extends AppCompatActivity {

    RecyclerView recy_view;
    MyDBHelper myDBHelper;
    SQLiteDatabase db;
    List<OutpayBean> arr1 = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_detail);
        initView();
        initData();
        OutpayAdapter adapter = new OutpayAdapter(PayDetailActivity.this,arr1);
        StaggeredGridLayoutManager st = new StaggeredGridLayoutManager(StaggeredGridLayoutManager.VERTICAL,1);
        recy_view.setLayoutManager(st);
        recy_view.setAdapter(adapter);
    }

    private void initView() {
        recy_view = findViewById(R.id.recy_view_outdetail);
        myDBHelper = new MyDBHelper(PayDetailActivity.this);
        db = myDBHelper.getWritableDatabase();
    }

    private void initData() {
        //从数据库查询所有已存数据，并取出
        Cursor cursor = db.rawQuery("select * from pay_out",null);
        if (cursor != null && cursor.moveToFirst()){
            do{

                @SuppressLint("Range") int myid = cursor.getInt(cursor.getColumnIndex("id"));
                @SuppressLint("Range") double mymoney = cursor.getDouble(cursor.getColumnIndex("outmoney"));
                @SuppressLint("Range") String mytime = cursor.getString(cursor.getColumnIndex("outtime"));
                @SuppressLint("Range") String mytype = cursor.getString(cursor.getColumnIndex("outtype"));
                @SuppressLint("Range") String mypayer = cursor.getString(cursor.getColumnIndex("outpayee"));
                @SuppressLint("Range") String myremark = cursor.getString(cursor.getColumnIndex("outremark"));
                OutpayBean outpayBean = new OutpayBean(myid,mymoney,mytime,mytype,mypayer,myremark);
                arr1.add(outpayBean);
            }while (cursor.moveToNext());
        }
        cursor.close();
    }

}